/*
=======================================================================

  BOTS Create Menu (NURSE/SCIENTIST ONLY)

=======================================================================
*/
#include "ui_local.h"
#include "ui_BOTS.h"

#define BOTS_CREATE_HEALTH			1
#define BOTS_CREATE_ADRENALINE		2
#define BOTS_CREATE_MEGAHEALTH		3
#define BOTS_CREATE_REGENERATION	4
#define BOTS_CREATE_BULLETS			5
#define BOTS_CREATE_SHELLS			6
#define BOTS_CREATE_GRENADES		7
#define BOTS_CREATE_ROCKETS			8
#define BOTS_CREATE_SLUGS			9
#define BOTS_CREATE_QUADDAMAGE		10
#define BOTS_CREATE_HASTE			11
#define BOTS_CREATE_BATTLESUIT		12

typedef struct 
{
  menuframework_s menu;  

  menutext_s	title;
  menutext_s	health;
  menutext_s	adrenaline;
  menutext_s	megahealth;
  menutext_s	regeneration;
  menutext_s	cancel;
} nurseCreate_t;

typedef struct 
{
  menuframework_s menu;  

  menutext_s	title;
  menutext_s	bullets;
  menutext_s	shells;
  menutext_s	grenades;
  menutext_s	rockets;
  menutext_s	slugs;
  menutext_s	quaddamage;
  menutext_s	haste;
  menutext_s	battlesuit;
  menutext_s	cancel;
} scientistCreate_t;

static nurseCreate_t		s_nurseCreate;
static scientistCreate_t	s_scientistCreate;

/*
=================
BOTS_CreateMenu_Event
callback routine
=================
*/
void BOTS_CreateMenu_Event( void *ptr, int notification ) 
{
	char item[100];
	item[0] = '\0';

	if( notification != QM_ACTIVATED )
		return;

	// any event will kill the menu
	UI_PopMenu();

	switch( ((menucommon_s*)ptr)->id ) 
	{
	case BOTS_CANCEL:
		break;
/////////////////////////////////////////////
// NURSE CREATE
//
	case BOTS_CREATE_HEALTH:
		strcpy(item, "health");
		break;
	case BOTS_CREATE_ADRENALINE:
		strcpy(item, "adrenaline");
		break;
	case BOTS_CREATE_MEGAHEALTH:
		strcpy(item, "megahealth");
		break;
	case BOTS_CREATE_REGENERATION:
		strcpy(item, "regeneration");
		break;

/////////////////////////////////////////////
// SCIENTIST CREATE
//
	case BOTS_CREATE_BULLETS:
		strcpy(item, "bullets");
		break;
	case BOTS_CREATE_SHELLS:
		strcpy(item, "shells");
		break;
	case BOTS_CREATE_SLUGS:
		strcpy(item, "slugs");
		break;
	case BOTS_CREATE_GRENADES:
		strcpy(item, "grenades");
		break;
	case BOTS_CREATE_ROCKETS:
		strcpy(item, "rockets");
		break;
	case BOTS_CREATE_QUADDAMAGE:
		strcpy(item, "quaddamage");
		break;
	case BOTS_CREATE_HASTE:
		strcpy(item, "haste");
		break;
	case BOTS_CREATE_BATTLESUIT:
		strcpy(item, "battlesuit");
		break;
		
	// oops - not a valid choice
	default:
		Com_Printf("%i is not a valid choice\n", ((menucommon_s*)ptr)->id);
		break;
	}

	if (item[0] != '\0')
		trap_Cmd_ExecuteText( EXEC_APPEND, va("UI_to_server_create %s\n", item));
}

/*
=================
BOTS_NurseCreateMenu_Init
=================
*/
void BOTS_NurseCreateMenu_Init() 
{
	int					y;
	char				info[MAX_INFO_STRING];
	uiClientState_t		cs;

	int	health			= 0;
	int adrenaline		= 0;
	int	megahealth		= 0;
	int regeneration	= 0;

	// get the config string and the data it holds
	trap_GetClientState( &cs );
	trap_GetConfigString( CS_BOTS_MENU + cs.clientNum, info, MAX_INFO_STRING );
	health			= atoi(Info_ValueForKey( info, "h"));
	adrenaline		= atoi(Info_ValueForKey( info, "a"));
	megahealth		= atoi(Info_ValueForKey( info, "m"));
	regeneration	= atoi(Info_ValueForKey( info, "r"));

	memset( &s_nurseCreate, 0 ,sizeof(nurseCreate_t) );
	s_nurseCreate.menu.wrapAround = qtrue;
	s_nurseCreate.menu.fullscreen = qfalse;

	y = 96;
	s_nurseCreate.title.generic.type	= MTYPE_PTEXT;
	s_nurseCreate.title.generic.flags	= QMF_CENTER_JUSTIFY;
	s_nurseCreate.title.generic.x		= 320;
	s_nurseCreate.title.generic.y		= y;
	s_nurseCreate.title.string			= "NURSE CREATE MENU";
	s_nurseCreate.title.color			= color_bots_menu;
	s_nurseCreate.title.style			= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	if (health)
	{
		y += BOTS_VERTICAL_SPACING;
		s_nurseCreate.health.generic.type		= MTYPE_PTEXT;
		s_nurseCreate.health.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
		s_nurseCreate.health.generic.x			= 320;
		s_nurseCreate.health.generic.y			= y;
		s_nurseCreate.health.generic.id			= BOTS_CREATE_HEALTH;
		s_nurseCreate.health.generic.callback	= BOTS_CreateMenu_Event; 
		s_nurseCreate.health.string				= "STANDARD HEALTH";
		s_nurseCreate.health.color				= color_bots_menu;
		s_nurseCreate.health.style				= UI_CENTER|UI_SMALLFONT;

		Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.health );
	}

	if (adrenaline)
	{
		y += BOTS_VERTICAL_SPACING;
		s_nurseCreate.adrenaline.generic.type		= MTYPE_PTEXT;
		s_nurseCreate.adrenaline.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
		s_nurseCreate.adrenaline.generic.x			= 320;
		s_nurseCreate.adrenaline.generic.y			= y;
		s_nurseCreate.adrenaline.generic.id			= BOTS_CREATE_ADRENALINE;
		s_nurseCreate.adrenaline.generic.callback	= BOTS_CreateMenu_Event; 
		s_nurseCreate.adrenaline.string				= "ADRENALINE";
		s_nurseCreate.adrenaline.color				= color_bots_menu;
		s_nurseCreate.adrenaline.style				= UI_CENTER|UI_SMALLFONT;

		if (BOTS_GetClassLevel() < 2 || adrenaline == 2) {
			s_nurseCreate.adrenaline.generic.flags |= QMF_GRAYED;
		}

		Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.adrenaline );
	}

	if (megahealth)
	{
		y += BOTS_VERTICAL_SPACING;
		s_nurseCreate.megahealth.generic.type		= MTYPE_PTEXT;
		s_nurseCreate.megahealth.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
		s_nurseCreate.megahealth.generic.x			= 320;
		s_nurseCreate.megahealth.generic.y			= y;
		s_nurseCreate.megahealth.generic.id			= BOTS_CREATE_MEGAHEALTH;
		s_nurseCreate.megahealth.generic.callback	= BOTS_CreateMenu_Event; 
		s_nurseCreate.megahealth.string				= "MEGAHEALTH";
		s_nurseCreate.megahealth.color				= color_bots_menu;
		s_nurseCreate.megahealth.style				= UI_CENTER|UI_SMALLFONT;

		if (BOTS_GetClassLevel() < 3 || megahealth == 2) {
			s_nurseCreate.megahealth.generic.flags |= QMF_GRAYED;
		}

		Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.megahealth );
	}

	if (regeneration)
	{
		y += BOTS_VERTICAL_SPACING;
		s_nurseCreate.regeneration.generic.type		= MTYPE_PTEXT;
		s_nurseCreate.regeneration.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
		s_nurseCreate.regeneration.generic.x		= 320;
		s_nurseCreate.regeneration.generic.y		= y;
		s_nurseCreate.regeneration.generic.id		= BOTS_CREATE_REGENERATION;
		s_nurseCreate.regeneration.generic.callback	= BOTS_CreateMenu_Event; 
		s_nurseCreate.regeneration.string			= "REGENERATION";
		s_nurseCreate.regeneration.color			= color_bots_menu;
		s_nurseCreate.regeneration.style			= UI_CENTER|UI_SMALLFONT;

		if (BOTS_GetClassLevel() < 4 || regeneration == 2) {
			s_nurseCreate.regeneration.generic.flags |= QMF_GRAYED;
		}

		Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.regeneration );
	}

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_nurseCreate.cancel.generic.type		= MTYPE_PTEXT;
	s_nurseCreate.cancel.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_nurseCreate.cancel.generic.x			= 320;
	s_nurseCreate.cancel.generic.y			= y;
	s_nurseCreate.cancel.generic.id			= BOTS_CANCEL;
	s_nurseCreate.cancel.generic.callback	= BOTS_CreateMenu_Event; 
	s_nurseCreate.cancel.string				= "CANCEL";
	s_nurseCreate.cancel.color				= color_bots_menu;
	s_nurseCreate.cancel.style				= UI_CENTER|UI_SMALLFONT;

	Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.title );
	//Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.health );
	//Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.adrenaline );
	//Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.megahealth );
	//Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.regeneration );
	Menu_AddItem( &s_nurseCreate.menu, &s_nurseCreate.cancel );
}

/*
=================
BOTS_ScientistCreateMenu_Init
=================
*/
void BOTS_ScientistCreateMenu_Init() 
{
	int y;
	char				info[MAX_INFO_STRING];
	uiClientState_t		cs;

	int	ammo			= 0;
	int quaddamage		= 0;
	int	haste			= 0;
	int battlesuit		= 0;

	// get the config string and the data it holds
	trap_GetClientState( &cs );
	trap_GetConfigString( CS_BOTS_MENU + cs.clientNum, info, MAX_INFO_STRING );
	ammo			= atoi(Info_ValueForKey( info, "a"));
	quaddamage		= atoi(Info_ValueForKey( info, "q"));
	haste			= atoi(Info_ValueForKey( info, "h"));
	battlesuit		= atoi(Info_ValueForKey( info, "b"));

	memset( &s_scientistCreate, 0 ,sizeof(scientistCreate_t) );
	s_scientistCreate.menu.wrapAround = qtrue;
	s_scientistCreate.menu.fullscreen = qfalse;

	y = 96;
	s_scientistCreate.title.generic.type	= MTYPE_PTEXT;
	s_scientistCreate.title.generic.flags	= QMF_CENTER_JUSTIFY;
	s_scientistCreate.title.generic.x		= 320;
	s_scientistCreate.title.generic.y		= y;
	s_scientistCreate.title.string			= "SCIENTIST CREATE MENU";
	s_scientistCreate.title.color			= color_bots_menu;
	s_scientistCreate.title.style			= UI_CENTER|UI_SMALLFONT;

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.bullets.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.bullets.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.bullets.generic.x			= 320;
	s_scientistCreate.bullets.generic.y			= y;
	s_scientistCreate.bullets.generic.id		= BOTS_CREATE_BULLETS;
	s_scientistCreate.bullets.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.bullets.string			= "BULLETS";
	s_scientistCreate.bullets.color				= color_bots_menu;
	s_scientistCreate.bullets.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.shells.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.shells.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.shells.generic.x			= 320;
	s_scientistCreate.shells.generic.y			= y;
	s_scientistCreate.shells.generic.id			= BOTS_CREATE_SHELLS;
	s_scientistCreate.shells.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.shells.string				= "SHELLS";
	s_scientistCreate.shells.color				= color_bots_menu;
	s_scientistCreate.shells.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.grenades.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.grenades.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.grenades.generic.x		= 320;
	s_scientistCreate.grenades.generic.y		= y;
	s_scientistCreate.grenades.generic.id		= BOTS_CREATE_GRENADES;
	s_scientistCreate.grenades.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.grenades.string			= "GRENADES";
	s_scientistCreate.grenades.color			= color_bots_menu;
	s_scientistCreate.grenades.style			= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.rockets.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.rockets.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.rockets.generic.x			= 320;
	s_scientistCreate.rockets.generic.y			= y;
	s_scientistCreate.rockets.generic.id		= BOTS_CREATE_ROCKETS;
	s_scientistCreate.rockets.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.rockets.string			= "ROCKETS";
	s_scientistCreate.rockets.color				= color_bots_menu;
	s_scientistCreate.rockets.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.slugs.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.slugs.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.slugs.generic.x			= 320;
	s_scientistCreate.slugs.generic.y			= y;
	s_scientistCreate.slugs.generic.id			= BOTS_CREATE_SLUGS;
	s_scientistCreate.slugs.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.slugs.string				= "SLUGS";
	s_scientistCreate.slugs.color				= color_bots_menu;
	s_scientistCreate.slugs.style				= UI_CENTER|UI_SMALLFONT;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.haste.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.haste.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.haste.generic.x			= 320;
	s_scientistCreate.haste.generic.y			= y;
	s_scientistCreate.haste.generic.id			= BOTS_CREATE_HASTE;
	s_scientistCreate.haste.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.haste.string				= "HASTE";
	s_scientistCreate.haste.color				= color_bots_menu;
	s_scientistCreate.haste.style				= UI_CENTER|UI_SMALLFONT;

	if (BOTS_GetClassLevel() < 2 || haste == 2) {
		s_scientistCreate.haste.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.battlesuit.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.battlesuit.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.battlesuit.generic.x			= 320;
	s_scientistCreate.battlesuit.generic.y			= y;
	s_scientistCreate.battlesuit.generic.id			= BOTS_CREATE_BATTLESUIT;
	s_scientistCreate.battlesuit.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.battlesuit.string				= "BATTLE SUIT";
	s_scientistCreate.battlesuit.color				= color_bots_menu;
	s_scientistCreate.battlesuit.style				= UI_CENTER|UI_SMALLFONT;

	if (BOTS_GetClassLevel() < 3 || battlesuit == 2) {
		s_scientistCreate.battlesuit.generic.flags |= QMF_GRAYED;
	}

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.quaddamage.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.quaddamage.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.quaddamage.generic.x			= 320;
	s_scientistCreate.quaddamage.generic.y			= y;
	s_scientistCreate.quaddamage.generic.id			= BOTS_CREATE_QUADDAMAGE;
	s_scientistCreate.quaddamage.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.quaddamage.string				= "QUAD DAMAGE";
	s_scientistCreate.quaddamage.color				= color_bots_menu;
	s_scientistCreate.quaddamage.style				= UI_CENTER|UI_SMALLFONT;

	if (BOTS_GetClassLevel() < 4 || quaddamage == 2) {
		s_scientistCreate.quaddamage.generic.flags |= QMF_GRAYED;
	}

	// skip a space
	y += BOTS_VERTICAL_SPACING;

	y += BOTS_VERTICAL_SPACING;
	s_scientistCreate.cancel.generic.type		= MTYPE_PTEXT;
	s_scientistCreate.cancel.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
	s_scientistCreate.cancel.generic.x			= 320;
	s_scientistCreate.cancel.generic.y			= y;
	s_scientistCreate.cancel.generic.id			= BOTS_CANCEL;
	s_scientistCreate.cancel.generic.callback	= BOTS_CreateMenu_Event; 
	s_scientistCreate.cancel.string				= "CANCEL";
	s_scientistCreate.cancel.color				= color_bots_menu;
	s_scientistCreate.cancel.style				= UI_CENTER|UI_SMALLFONT;

	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.title );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.bullets );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.shells );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.grenades );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.rockets );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.slugs );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.haste );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.battlesuit );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.quaddamage );
	Menu_AddItem( &s_scientistCreate.menu, &s_scientistCreate.cancel );
}

void BOTS_CreateMenu_f( int classtype ) 
{
	// force as top level menu
	uis.menusp = 0;  

	// set menu cursor to a nice location
	uis.cursorx = 319;
	uis.cursory = 80;
	
	switch (classtype)
	{
	case BOTS_NURSE:
		{
			// setup the menu structure
			BOTS_NurseCreateMenu_Init();

			// show the menus
			UI_PushMenu( &s_nurseCreate.menu );
		}
		break;
	case BOTS_SCIENTIST:
		{
			// setup the menu structure
			BOTS_ScientistCreateMenu_Init();

			// show the menus
			UI_PushMenu( &s_scientistCreate.menu );
		}
		break;
	}// switch
}
